package com.project.smarthome.common.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * Created by L on 2016/12/2.
 */

public class ObjectUtil {

    public static <T extends Serializable> T deepCopy(T object) {
        try {
            ByteArrayOutputStream bop = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bop);
            oos.writeObject(object);
            ByteArrayInputStream bis = new ByteArrayInputStream(bop.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            return (T) ois.readObject();
        } catch (Exception e) {
        }

        return null;
    }
}
